function deepClone(obj, hash = new WeakMap()) {
  if (hash.has(obj)) {
      return obj;
  }
  let res = null;
  const reference = [Date, RegExp, Set, WeakSet, Map, WeakMap, Error];

  if (reference.includes(obj?.constructor)) {
      res = new obj.constructor(obj);
  } else if (Array.isArray(obj)) {
      res = [];
      obj.forEach((e, i) => {
          res[i] = deepClone(e);
      });
  } else if (typeof obj === "object" && obj !== null) {
      res = {};
      for (const key in obj) {
          if (Object.hasOwnProperty.call(obj, key)) {
              res[key] = deepClone(obj[key]);
          }
      }
      hash.set(obj, res);
  } else {
      res = obj;
  }
  return res;
}
let a = {
  a : {
    a : {
      a : 1
    }
  },
  b(){
    console.log('b')
  }
}

console.log(deepClone(a).b)
